package chapter2;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class TestDropdown {
	
	WebDriver driver;
	
	@Before
	public void setUp()
	{
		driver = new FirefoxDriver();
		driver.get("http://dl.dropbox.com/u/55228056/Config.html");
	}

	@Test
	public void testDropdown()
	{
		
	//Get the Dropdown as a Select using its name attribute
	Select make = new Select(driver.findElement(By.name("make")));
	//Verify Dropdown does not support multiple selection
	assertFalse(make.isMultiple());
	//Verify Dropdown has four options for selection
	assertEquals(4, make.getOptions().size());
	//With Select class we can select an option in Dropdown using
	//Visible Text
	make.selectByVisibleText("Honda");
	assertEquals("Honda", make.getFirstSelectedOption().getText());
	//or we can select an option in Dropdown using value attribute
	make.selectByValue("audi");
	assertEquals("Audi", make.getFirstSelectedOption().getText());
	//or we can select an option in Dropdown using index
	make.selectByIndex(0);
	assertEquals("BMW", make.getFirstSelectedOption().getText());
	
	}
	
	@After
	public void tearDwon()
	{
		driver.quit();
	}
	

}
